<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>doppler</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="divz.html" title="divz" />
    <link rel="next" href="downsamp.html" title="downsamp" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">doppler</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="divz.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="downsamp.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="doppler"></a>
      <div class="titlepage"></div>
      <a id="IndexDoppler" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">doppler</span>
        </h2>
        <p>doppler — 
      A fast and robust method for approximating sound propagation, achieving convincing Doppler shifts without having to solve equations.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp99730912"></a>
        <h2>Description</h2>
        <p>
      A fast and robust method for approximating sound propagation, achieving convincing Doppler shifts without having to solve equations. The method computes frequency shifts based on reading an input delay line at a delay time computed from the distance between source and mic and the speed of sound. One instance of the opcode is required for each dimension of space through which the sound source moves. If the source sound moves at a constant speed from in front of the microphone, through the microphone, to behind the microphone, then the output will be frequency shifted above the source frequency at a constant frequency while the source approaches, then discontinuously will be shifted below the source frequency at a constant frequency as the source recedes from the microphone. If the source sound moves at a constant speed through a point to one side of the microphone, then the rate of change of position will not be constant, and the familiar Doppler frequency shift typical of a siren or engine approaching and receding along a road beside a listener will be heard.
</p>
      </div>
      <div class="refsect1">
        <a id="idp99800672"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ashifted <span class="command"><strong>doppler</strong></span> asource, ksourceposition, kmicposition [, isoundspeed, ifiltercutoff]</pre>
      </div>
      <div class="refsect1">
        <a id="idp99802832"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>isoundspeed</em></span> (optional, default=340.29) -- Speed of sound in meters/second.
    </p>
        <p>
      <span class="emphasis"><em>ifiltercutoff</em></span> (optional, default=6) -- Rate of updating the position smoothing filter, in cycles/second.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp99805424"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>asource</em></span> -- Input signal at the sound source.
    </p>
        <p>
      <span class="emphasis"><em>ksourceposition</em></span> -- Position of the source sound in meters. The distance between source and mic should not be changed faster than about 3/4 the speed of sound.
    </p>
        <p>
      <span class="emphasis"><em>kmicposition</em></span> -- Position of the recording microphone in meters. The distance between source and mic should not be changed faster than about 3/4 the speed of sound.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp99809024"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the doppler opcode. It uses the file <a class="ulink" href="examples/doppler.csd" target="_top"><em class="citetitle">doppler.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp99810880"></a>
          <p class="title">
            <strong>Example 202. Example of the doppler opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;RT audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o doppler.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 48000
<span class="ohdr">ksmps</span> <span class="op">=</span> 128
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="oblock">instr</span> 1

iattack       <span class="opc">init</span>    0.05
irelease      <span class="opc">init</span>    0.05
isustain      <span class="opc">init</span>    p3
p3            <span class="opc">init</span>    iattack <span class="op">+</span> isustain <span class="op">+</span> irelease
kdamping      <span class="opc">linseg</span>  0.0, iattack, 1.0, isustain, 1.0, irelease, 0.0	
kmic          <span class="opc">init</span>    4
              <span class="comment">; Position envelope, with a changing rate of change of position.</span>
<span class="comment">;             transeg a   dur   ty  b      dur    ty  c    dur    ty d</span>
kposition     <span class="opc">transeg</span> 4, p3<span class="op">*</span>.4, 0, 120,   p3<span class="op">*</span>.3, <span class="op">-</span>3, 50,   p3<span class="op">*</span>.3, 2, 4
ismoothinghz  <span class="opc">init</span>    6
ispeedofsound <span class="opc">init</span>    340.29
asignal       <span class="opc">vco2</span>    0.5, 110
aoutput       <span class="opc">doppler</span> asignal, kposition, kmic, ispeedofsound, ismoothinghz
              <span class="opc">outs</span>    aoutput<span class="op">*</span>kdamping, aoutput <span class="op">*</span> kdamping
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span>1	0.0	20	
<span class="stamnt">e</span>1
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp99817248"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author of algorithm: Peter Brinkmann</td>
          </tr>
          <tr>
            <td>Author of opcode: Michael Gogins</td>
          </tr>
          <tr>
            <td>January 2010</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound version 5.11</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="divz.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="downsamp.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">divz </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> downsamp</td>
        </tr>
      </table>
    </div>
  </body>
</html>
